<?php
class Buku_model extends CI_Model {

		function __construct(){
			parent::__construct(); 
			
			}
		
		
	function getBuku($query=FALSE,$id_buku=FALSE,$cari=FALSE,$limit=FALSE,$offset=FALSE){
		if ($query == 'list'){
			$this->db->limit($limit,$offset);
			$this->db->join('tb_penerbit','tb_penerbit.id_penerbit=tb_buku.id_penerbit');
			$this->db->order_by('id_buku','desc');
			return $this->db->get('tb_buku')->result_array();
		}
		elseif ($query == 'by_id' ){
				$this->db->join('tb_kategori','tb_kategori.id_kategori=tb_buku.id_kategori');
				$this->db->join('tb_penerbit','tb_penerbit.id_penerbit=tb_buku.id_penerbit');
				$this->db->where('id_buku',$id_buku);
				return $this->db->get('tb_buku')->row();
		}
		elseif ($query == 'cari'){
				$this->db->limit($limit,$offset);
				$this->db->join('tb_penerbit','tb_penerbit.id_penerbit=tb_buku.id_penerbit');
				$this->db->order_by('id_buku','desc');
				$this->db->like('judul',$cari);
				
				return $this->db->get('tb_buku')->result_array();
						
		}
	
	
	}
	
	function addBuku($data) {
		$this->db->insert('tb_buku',$data);
	
	}
	function editBuku($id,$data) {
		$this->db->where('id_buku',$id);
		$this->db->update('tb_buku',$data);
			
	}
	function deleteBuku($id) {
		$this->db->where('id_buku',$id);
		$this->db->delete('tb_buku');
		
	
	}
		
}


?>